import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//导入element相关内容
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

//全局引入axios和qs框架
import axios from 'axios';
window.axios=axios;
import qs from 'qs';
window.qs=qs;
//定义全局的Url
const BASE_URL='http://localhost:8080';
window.BASE_URL=BASE_URL;
//定义全局方法
window.getUser=()=>{
    return localStorage.user?JSON.parse(localStorage.user):null;
}

const app = createApp(App)
app.use(ElementPlus)//使用elementplus框架
app.use(store).use(router).mount('#app')
//在Vue实例中添加全局实现 可供任意页面在template标签内访问
app.config.globalProperties.BASE_URL=BASE_URL;
//注册
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

/** 解决页面重置报ResizeObserver错误问题 */
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}